import { Shape } from "XrFrame/components";
import { CanvasContext } from "./designType";
import { Dimension } from "./Dimension";
import { Glass } from "./Glass";
import { Handle } from "./Handle";

export class WindowOpen {
  constructor(
    public direction: 'left' | 'right' | 'top' | 'bottom',
    public type: 'swing' | 'slide' | 'tilt',
    public dimension: Dimension,   // 窗扇的尺寸
    public handlePosition: 'left' | 'right' | 'center' | 'top' | 'bottom', // 把手位置
    public handle: Handle,
    public shape: Shape,
    public glass: Glass
  ) {}

  draw(ctx: CanvasContext): void {
    ctx.beginPath();
    ctx.rect(this.dimension.length, this.dimension.width, this.dimension.width, this.dimension.height);
    ctx.stroke();

    // 绘制把手
    const { length, width } = this.dimension;
    switch (this.handlePosition) {
      case 'left':
        ctx.arc(length, width + this.dimension.height / 2, 5, 0, Math.PI * 2);
        break;
      case 'right':
        ctx.arc(length + this.dimension.width, width + this.dimension.height / 2, 5, 0, Math.PI * 2);
        break;
      case 'center':
        ctx.arc(length + this.dimension.width / 2, width + this.dimension.height / 2, 5, 0, Math.PI * 2);
        break;
      case 'top':
        ctx.arc(length + this.dimension.width / 2, width, 5, 0, Math.PI * 2);
        break;
      case 'bottom':
        ctx.arc(length + this.dimension.width / 2, width + this.dimension.height, 5, 0, Math.PI * 2);
        break;
    }
    ctx.fill();
  }
}
